//
//  SDNetWorkTool.m
//  SuperDoctor
//
//  Created by 李忠 on 7/5/16.
//  Copyright © 2016 SD. All rights reserved.
//

#import "SDNetWorkTool.h"

@implementation SDNetWorkTool

+ (instancetype)shareManager{
    static SDNetWorkTool *instance;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration];
        
        //config.timeoutIntervalForRequest = 10;
        instance = [[SDNetWorkTool alloc] initWithSessionConfiguration:config];
        //2.可接受格式
        instance.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/html", nil];
        
        //3.请求格式（默认：二进制）
        instance.requestSerializer = [AFJSONRequestSerializer serializer];
        //MARK: 请求超时
        instance.requestSerializer.timeoutInterval = 10.0;
    });
    return instance;
}


//GET请求
- (void)GET_RequestWithUrlString:(NSString *)urlString parmas:(NSDictionary *)params successBloock:(SuccessCompletedBlock)success failureBlock:(FailureCompletedBlock)failure{
    [[SDNetWorkTool shareManager] GET:urlString parameters:params progress:^(NSProgress * _Nonnull downloadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        success(responseObject);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        failure(error);
    }];

}

- (void)POST_RequestWithUrlString:(NSString *)urlString parmas:(NSDictionary *)params successBloock:(SuccessCompletedBlock)success failureBlock:(FailureCompletedBlock)failure{
    [[SDNetWorkTool shareManager] POST:urlString parameters:params progress:^(NSProgress * _Nonnull downloadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        success(responseObject);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        failure(error);
    }];

}

@end
